<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\business\EhrHelper;
use yii\helpers\ArrayHelper;
use kartik\tree\TreeView;
use common\models\Department;
use leandrogehlen\treegrid\TreeGrid;

/* @var $this yii\web\View */
/* @var $searchModel common\models\CompanySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $models array */
$this->registerJsFile('/js/zTree_v3-master/js/jquery.ztree.all.js', [
    'depends' => 'backend\assets\AppAsset',
]);
$this->registerCssFile('/js/zTree_v3-master/css/zTreeStyle/zTreeStyle.css', [
    'depends' => 'backend\assets\AppAsset',
]);
//dmstr\web\AdminLteAsset::register($this);

$this->registerCssFile('/js/zTree_v3-master/css/demo.css', [
    'depends' => 'backend\assets\AppAsset',
]);

$this->title = Yii::t('app', 'Companies');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="company-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a(Yii::t('app', 'Create Company'), ['create'], ['class' => 'btn btn-success']) ?>
        <?= Html::a(Yii::t('app', 'Sync Company from HR'), ['sync-from-hr'], ['class' => 'btn btn-primary', 'target'=>'_blank']) ?>
    </p>
    <?php
    try {
        $gv = GridView::widget([
            'tableOptions' => ['class' => 'table table-condensed table-bordered table-striped table-hover'],
            'pager' => [
//            'class'          => GoPager::className(),
                'nextPageLabel'  => Yii::t('app', 'Next Page'),
                'prevPageLabel'  => Yii::t('app', 'Previous Page'),
                'firstPageLabel' => Yii::t('app', 'First Page'),
                'lastPageLabel'  => Yii::t('app', 'Last Page'),
                'options' => [
                    'class' => 'pagination pagination-sm m-t-none m-b-none',
                ],
            ],
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'columns' => [
                [
                    'class' => 'yii\grid\SerialColumn',
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 25px;'],
                ],

//            'FID',
//            'FIDNUM',
//            'FNAME_L1',
//            'FNAME_L2',
                [
                    'label' => Yii::t('app', 'Employee Name'),
                    'attribute' => 'FNAME_L2',
                    'contentOptions' => ['style' => 'width: 100px;'],
                ],
//            'FNAME_L3',
                // 'FNUMBER',
                [
                    'label' => Yii::t('app', 'Employee Number'),
                    'attribute' => 'FNUMBER',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                ],
                // 'FDESCRIPTION_L1',
                // 'FDESCRIPTION_L2',
                // 'FDESCRIPTION_L3',
                // 'FSIMPLENAME',
                [
                    'label' => Yii::t('app', 'Gender'),
                    'attribute' => 'FGENDER',
                    'value' => function ($model, $key, $index, $column) {
                        return EhrHelper::getGenderByIntValue($model['FGENDER']);
                    },
                    'filter' => EhrHelper::getGender_map(),
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                ],
//            'FBIRTHDAY',
                [
                    'label' => Yii::t('app', 'Birthday'),
                    'attribute' => 'FBIRTHDAY',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                ],
//            'FEMAIL:email',
                [
                    'label' => Yii::t('app', 'Email'),
                    'attribute' => 'FEMAIL',
                    'format' => 'email',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                    'contentOptions' => ['style' => 'width: 150px;'],
                ],
                // 'FADDRESS_L1',
//            'FADDRESS_L2',
//            [
//                'label' => Yii::t('app', 'Address'),
//                'attribute' => 'FADDRESS_L2',
//                'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
//                'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
//            ],
                // 'FADDRESS_L3',
                // 'FSTATE',
                // 'FHOMEPHONE',
                // 'FOFFICEPHONE',
//            'FCELL',
                [
                    'label' => Yii::t('app', 'Mobile'),
                    'attribute' => 'FCELL',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 120px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 120px;'],
                ],
                // 'FBACKUPCELL',
                // 'FBACKUPEMAIL:email',
                // 'FRTX',
                // 'FIDCARDNO',
                [
                    'label' => Yii::t('app', 'Id Card No'),
                    'attribute' => 'FIDCARDNO',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 120px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 120px;'],
                ],
                // 'FIDCARDADRESS_L1',
                // 'FIDCARDADRESS_L2',
                // 'FIDCARDADRESS_L3',
                // 'FPASSPORTNO',
                // 'FOLDNAME_L1',
                // 'FOLDNAME_L2',
                // 'FOLDNAME_L3',
                // 'FHEIGHT',
                // 'FNATIVEPLACE_L1',
                // 'FNATIVEPLACE_L2',
                [
                    'label' => Yii::t('app', 'Native Place'),
                    'attribute' => 'FNATIVEPLACE_L2',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 120px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 120px;'],
                ],
                // 'FNATIVEPLACE_L3',
                // 'FBLOODTYPE',
                [
                    'attribute' => 'FBLOODTYPE',
                    'label' => Yii::t('app', 'Blood Type'),
                    'value' => function ($model) {
                        return EhrHelper::getBloodTypeByIntValue($model['FBLOODTYPE']);
                    },
                    'filter' => EhrHelper::getBloodType_map(),
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                ],
                // 'FCREATORID',
                // 'FCREATETIME',
                // 'FLASTUPDATEUSERID',
                // 'FLASTUPDATETIME',
                // 'FKACLASSFICATIONID',
//            'FWEDID',
                [
                    'attribute' => 'FWEDID',
                    'label' => Yii::t('app', 'Wed Status'),
                    'value' => function ($model) {
                        return EhrHelper::getWedStrById($model['FWEDID']);
                    },
                    'filter' => ArrayHelper::map(\common\models\kingdee\HrWed::find()->all(), 'FID', 'FNAME_L2'),
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                ],
//             'FHEALTHID',
//            [
//                'attribute' => 'FHEALTHID',
//                'label' => Yii::t('app', 'Health Condition'),
//                'value' => function ($model) {
//                    return EhrHelper::getHealthStrById($model['FHEALTHID']);
//                },
//                'filter' => ArrayHelper::map(\common\models\kingdee\HrHealth::find()->all(), 'FID', 'FNAME_L2'),
//                'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
//                'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
//            ],
                // 'FPOLITICALFACEID',
                // 'FSTANDINGID',
//             'FFOLKID',
                [
                    'attribute' => 'FFOLKID',
                    'label' => Yii::t('app', 'Folk'),
                    'value' => function ($model) {
                        return EhrHelper::getFolkStrById($model['FFOLKID']);
                    },
                    'filter' => ArrayHelper::map(\common\models\kingdee\HrFolk::find()->all(), 'FID', 'FNAME_L2'),
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                ],
                // 'FBIRTHID',
                // 'FCONTROLUNITID',
                // 'FHRORGUNITID',
                // 'FRESIDENCEPLACE',
                // 'FLENOFACTUALSERVICE',
                // 'FEMPLOYEETYPEID',
                // 'FHIGHESTTECHPOSTID',
                // 'FHIGHESTDEGREEID',
                // 'FEMPLOYEECLASSIFYID',
                // 'FDELETEDSTATUS',
                // 'FLCMRATIONLEVELID',
//             'FNATIONALITYID',
                [
                    'attribute' => 'FNATIONALITYID',
                    'label' => Yii::t('app', 'Nationality'),
                    'value' => function ($model) {
                        return EhrHelper::getNationalityStrById($model['FNATIONALITYID']);
                    },
                    'filter' => ArrayHelper::map(\common\models\kingdee\Nationality::find()->all(), 'FID', 'FNAME_L2'),
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                ],
                // 'FCHECKSTATE',
                // 'FINDEX',
                // 'FEMPLOYTECHPOSTID',
                // 'FHIGHESTSUBDEGREEID',
                // 'FZDY1',
                // 'FZDY2',
                // 'FZDY3',
                // 'FZDY4',
                // 'FZDY5',
                // 'FZDY6',
                // 'FZDY7',
                // 'FZDY8',
                // 'FZDY9',
                // 'FZDY10',
                // 'FZDY11',
                // 'FZDY12',
                // 'FZDY13',
                // 'FZDY14',
                // 'FZDY15',
                // 'FZDY16',
                // 'FZDY17',
                // 'FZDY18',
                // 'FZDY19',
                // 'FZDY20',
                // 'FZDY21',
                // 'FZDY22',
                // 'FZDY23',
                // 'FZDY24',
                // 'FZDY25',
                // 'FZDY26',
                // 'FFULLNAMEPINGYIN',
                // 'FSIMPLENAMEPINGYIN',
                // 'FISSTANDBY',
                // 'FISSTANDBYCADRE',
                // 'FHIGHESTCOMPETENCYID',
                // 'FNAMEPINYIN',
                // 'FNAMESHORTPINYIN',
//             'FREGRESIDENCEID',
                [
                    'attribute' => 'FREGRESIDENCEID',
                    'label' => Yii::t('app', 'Regpermresidence'),
                    'value' => function ($model) {
                        return EhrHelper::getRegpermresidenceStrById($model['FREGRESIDENCEID']);
                    },
                    'filter' => ArrayHelper::map(\common\models\kingdee\Regpermresidence::find()->all(), 'FID', 'FNAME_L2'),
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                ],
                // 'FHJADDRESS',
                // 'FIDCARDADDRESS',
//            [
//                'label' => Yii::t('app', 'Id Card Address'),
//                'attribute' => 'FIDCARDADDRESS',
//                'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 120px;'],
//                'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 120px;'],
//            ],
                // 'FHOMEPLACE',
                // 'FEFFDT',
                // 'FLEFFDT',
                // 'FHISTORYRELATEID',
                // 'FIDCARDBEGINDATE',
                // 'FIDCARDENDDATE',
                // 'FEXTENDFIELDNUMONE',
                // 'FPROTOCOL',
                // 'FIDCARDISSUEORG',
                // 'CFTC',
                // 'CFTSRYBSID',
                // 'CFFXDW',
                // 'CFGATXZ',
                // 'CFPTTXZ',
                // 'CFISJZZ',
                // 'CFJHSYQKID',
                // 'CFZVCSNY',
                // 'CFISGG',
                // 'CFISQB',
                // 'CFSBGXDW',
                // 'CFYHKXX',
                // 'CFISXSCT',
                // 'CFRDYZNX',
                // 'CFSXRQ',
                // 'CFJFSXRQ',
                // 'CFJFNX',
                // 'CFJFJZRQ',
                // 'CFGZD',
                // 'CFRDTSJ',

                ['class' => 'yii\grid\ActionColumn'],
            ],
        ]);
    } catch (Exception $e) {
    }
    ?>
</div>
<div class="row">
    <div class="col-md-4 col-sm-4 col-xs-4">

        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">部门树</h3>

                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                    </button>
                    <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body" style="max-height: 100px">
                <ul id="treeDemo" class="ztree"></ul>
                <div class="overlay">
                    <i class="fa fa-refresh fa-spin"></i>
                </div>
            </div>
            <!-- /.box-body -->
            <div class="box-footer clearfix">
                <div class="btn-group">
                    <button type="button" class="btn btn-default"><i class="fa fa-plus"></i></button>
                    <button type="button" class="btn btn-default"><i class="fa fa-align-center"></i></button>
                    <button type="button" class="btn btn-default"><i class="fa fa-align-right"></i></button>
                </div>
            </div>
            <!-- /.box-footer -->
        </div>
    </div>
    <div class="col-md-8 col-sm-8 col-xs-8">
        <?=$gv ?>
    </div>
</div>

<script>
    <?php $this->beginBlock('js_running')?>

    var zTreeObj;
    // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
    var setting = {
        async: {
            enable: true,
            url: "/department/ajax-department",
            autoParam:["id", "name", "number"]
        },
        check : {
            enable: true,
            chkStyle: "checkbox",
            chkboxType: { "Y": "ps", "N": "ps" }
        },
        callback : {
            onAsyncSuccess: function (event, treeId, treeNode, msg) {
                // alert(msg);
                $('.overlay').html('');
            }
            // ,
            // onClick: function (event, treeId, treeNode) {
            //     alert(treeNode.tId + ", " + treeNode.name);
            // }
        }
    };
    // zTree 的数据属性，深入使用请参考 API 文档（zTreeNode 节点数据详解）
    // var zNodes = [
    //     {name:"neil1", open:true, children:[
    //             {name:"test1_1"}, {name:"test1_2"}]},
    //     {name:"neil2", open:true, children:[
    //             {name:"test2_1"}, {name:"test2_2"}]}
    // ];
    $(document).ready(function(){
        // zNodes = [
        //     {name:"neil1", open:true, children:[
        //             {name:"test1_1"}, {name:"test1_2"}]},
        //     {name:"neil2", open:true, children:[
        //             {name:"test2_1"}, {name:"test2_2"}]}
        // ];

        // zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        zTreeObj = $.fn.zTree.init($("#treeDemo"), setting);
    });
    <?php $this->endBlock()?>
</script>
<?php
$this->registerJs($this->blocks['js_running'], \yii\web\View::POS_END)
?>
